//联合类型
let test: string | number;

test = 1;

test = "Hello";
// ----------------------------------------------------
//类型别名
type MyType = (string | number)[];

//联合类型数组
const arr: MyType = [1, 2, 3, 4, 5, "hello"];
const arr2: MyType = ["牛波一"];
console.log(arr2);


// ------------------------------------------------------------

arr.forEach((item) => {
  if (typeof item === "string") {
    console.log("安全调用string 方法", item.toUpperCase());
  } else if (typeof item === "number") {
    console.log("安全调用number 方法", item.toFixed(2));
  }
});
